package singleton.pattern;

/**
 * Created by DELL
 * Date: 2019/9/28.
 * Time: 13:24
 */
class MakeACaption {
    private static MakeACaption _caption;
    //We make the constructor private to prevent the use of "new"
    private MakeACaption(){}

    public static MakeACaption get_caption() {
        if(_caption == null){
            _caption = new MakeACaption();
            System.out.println("New Caption selected in our team");
        }else{
            System.out.println("You already have a Caption for your team");
            System.out.println("Send him for the toss");
        }
        return _caption;
    }
}
//Main
class SingletonPatternEX{
    public static void main(String[] args) {
        System.out.println("************Singletion Pattern Demo**************\n");
        System.out.println("Try to make a Caption in our team");
        MakeACaption c1 = MakeACaption.get_caption();
        System.out.println("Trying to make another Caption for our team");
        MakeACaption c2 =  MakeACaption.get_caption();

        if(c1 == c2){
            System.out.println("c1 and c2 are same instance");
        }
    }
}